package webcert.ch03.ex0303;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

//@WebServlet(name = "Dispatcher", urlPatterns = "/Dispatcher")
public class Dispatcher extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String mode = request.getParameter("mode");
        RequestDispatcher requestDispatcher = request.getRequestDispatcher("/Receiver/pathInfo?fruit=orange");

        if (mode == "forward") {
            requestDispatcher.forward(request, response);
        }

        if (mode == "include") {
            requestDispatcher.include(request, response);
        }

        PrintWriter out = response.getWriter();
        out.write("This is Dispatcher servlet");

    }
}
